<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
/**
 * User model
 *
 * @author thanhtv6075
 *
 */
class User extends Eloquent implements UserInterface, RemindableInterface {

	use UserTrait, RemindableTrait;

	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 't_user';

	protected $primaryKey = 'user_id';

	/**
	 * The attributes excluded from the model's JSON form.
	 *
	 * @var array
	 */
	protected $hidden = array('hash_password', 'remember_token');

	protected $guarded = array('user_id');
	protected $fillable = array('name', 'user_id', 'password', 'hash_password', 'type', 'shop_id', 'email');

	/**
	 * Disable timestamps
	 *
	 * @var boolean
	 */
	public $timestamps = false;
	/**
	 * The validator when register user
	 *
	 * @var array
	 */
	/**
	 * V call user type
	 *
	 * @var interger
	 */
	public static $vCallUser = 7;

	public static $rules = array(
			'user_id' => 'required|min:3',
			'password' => 'required|min:6',
			'password_confirmation' => 'required|min:6|same:password',
			'name' => 'required|min:5|max:50',
			'email' => 'required|email|max:255',
	);

	/**
	 * Get the unique identifier for the user.
	 *
	 * @return mixed
	 */
	public function getAuthIdentifier()
	{
		return $this->getKey();
	}

	/**
	 * Get the password for the user.
	 *
	 * @return string
	 */
	public function getAuthPassword()
	{
		return $this->hash_password;
	}

	/**
	 * set hash_password with hash
	 * @param string $value
	 */
	public function setHashPasswordAttribute($password)
	{
		$this->attributes['hash_password'] = Hash::make($password);
	}

	/**
	 * Get the e-mail address where password reminders are sent.
	 *
	 * @return string
	 */
	public function getReminderEmail()
	{
		return $this->email;
	}

	/**
	 * get remember token
	 *
	 * @return string
	 */
	public function getRememberToken(){
		return $this->remember_token;
	}

	/**
	 * Set remember token
	 * @param string $value
	 */
	public function setRememberToken($value){
		$this->remember_token = $value;
	}

	/**
	 * get remember token field name in db
	 * @return string
	 */
	public function getRememberTokenName(){
		return 'remember_token';
	}
	
	/**
	 * get user name by user id
	 * @return string
	 */
	public static function getUserName($user_id) {
		return DB::table('t_user')->where('user_id', $user_id)->pluck('name');
	}
}
